package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.pojo.Course_Lesson;
import com.lagou.pojo.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.utils.DateUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : liuchangling
 * @Descrition :
 * @Date： Created in 11:53 上午 2021/6/11
 */
public class CourseContentServiceImpl implements CourseContentService {
    CourseContentDao courseContentDao = new CourseContentDaoImpl();

    @Override
    public List<Course_Lesson> findLessonByCourseId(int id) {
        return courseContentDao.findLessonByCourseID(id);
    }

    @Override
    public List<Course_Section> findSectionByCourseId(int id) {
        return courseContentDao.findSectionByCourseId(id);
    }

    @Override
    public Course findCourseById(int course_id) {
        return courseContentDao.findCourseById(course_id);
    }

    @Override
    public String saveSection(Course_Section courseSection) {
        //补全课程营销信息
        String strDate = DateUtils.getDateFormart();
        courseSection.setCreate_time(strDate);
        courseSection.setUpdate_time(strDate);
        courseSection.setStatus(1);

        int row = courseContentDao.saveSection(courseSection);

        if (row > 0) {
            String result = StatusCode.SUCCESS.toString();
            return result;
        } else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateSection(Course_Section courseSection) {
        String strDate=DateUtils.getDateFormart();
        courseSection.setUpdate_time(strDate);
        int row=courseContentDao.updateSection(courseSection);
        if(row>0){
            String result=StatusCode.SUCCESS.toString();
            return result;
        }else{
            String result=StatusCode.FAIL.toString();
            return result;
        }
    }


    @Override
    public String updateCourse_SectionStatus(Course_Section course_section) {
        String strDate=DateUtils.getDateFormart();
        course_section.setUpdate_time(strDate);
        int row=courseContentDao.updateSectionStatus(course_section);

        if(row > 0){
            String result=StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result=StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String saveLesson(Course_Lesson courseLesson) {
        //补全课程营销信息
        String strDate = DateUtils.getDateFormart();
        courseLesson.setCreate_time(strDate);
        courseLesson.setUpdate_time(strDate);
        courseLesson.setStatus(1);

        int row = courseContentDao.saveLesson(courseLesson);

        if (row > 0) {
            String result = StatusCode.SUCCESS.toString();
            return result;
        } else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateLesson(Course_Lesson courseLesson) {
        String strDate=DateUtils.getDateFormart();
        courseLesson.setUpdate_time(strDate);
        int row = courseContentDao.updateLesson(courseLesson);
        if(row>0){
            String result=StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result=StatusCode.FAIL.toString();
            return result;
        }
    }


}
